package cn.xinfei.xdecision.datasource.mongodb;


import org.bson.types.Decimal128;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.convert.WritingConverter;

import java.math.BigDecimal;

/**
 * @author xiaomifeng1010
 * @version 1.0
 * @date: 2022/7/22 16:50
 * @Description  java-->mongo  即BigDecimal转换为mongodb中的Decimal128的转换器
 */
@WritingConverter
public class BigDecimalToDecimal128Converter implements Converter<BigDecimal, Decimal128> {
    /**
     * Convert the source object of type {@code S} to target type {@code T}.
     *
     * @param source the source object to convert, which must be an instance of {@code S} (never {@code null})
     * @return the converted object, which must be an instance of {@code T} (potentially {@code null})
     * @throws IllegalArgumentException if the source cannot be converted to the desired target type
     */
    @Override
    public Decimal128 convert(BigDecimal source) {
        return new Decimal128(source);
    }
}